package com.youku.utils
{
   import flash.system.Capabilities;
   
   public class FlashVersionCheck extends Object
   {
      
      public function FlashVersionCheck() {
         super();
      }
      
      public static const MIN_VERSION_FOR_P2P:String = "10,1,85,3";
      
      public static const MIN_VERSION_FOR_STAGEVIDEO:String = "10,3,181,14";
      
      public static const MIN_VERSION_FOR_NEWVERSION:String = "11,2";
      
      public static const versionCapabDict:Object = 
         {
            "11,5,502,110":true,
            "11,4,402,287":true,
            "11,4,402,278":true,
            "11,4,402,265":true,
            "11,3,300,273":true,
            "11,3,300,271":true,
            "11,3,300,268":true,
            "11,3,300,265":true,
            "11,3,300,262":true,
            "11,3,300,257":true,
            "11,2,202,251":true,
            "11,2,202,243":true,
            "11,2,202,238":true,
            "11,2,202,235":true,
            "11,2,202,233":true,
            "11,2,202,223":true,
            "11,2,202,228":true,
            "11,1,102,63":true,
            "11,1,102,62":true,
            "11,1,102,55":true,
            "11,0,1,152":true,
            "10,3,183,43":true,
            "10,3,183,29":true,
            "10,3,183,25":true,
            "10,3,183,23":true,
            "10,3,183,20":true,
            "10,3,183,18":true,
            "10,3,183,16":true,
            "10,3,183,15":true,
            "10,3,183,11":true,
            "10,3,183,10":true,
            "10,3,183,7":true,
            "10,3,183,5":true,
            "10,3,181,34":true,
            "10,3,181,26":true,
            "10,3,181,22":true,
            "10,3,181,16":true,
            "10,3,181,14":true,
            "10,2,159,1":true,
            "10,2,153,1":true,
            "10,2,152,32":true,
            "10,2,152,26":true,
            "10,1,102,64":true,
            "10,1,85,3":true,
            "9,0,289,0":false,
            "9,0,283,0":false
         };
      
      public static function checkVersionForCapab() : Boolean {
         var _loc1_:String = Capabilities.version.split(" ")[0];
         if(_loc1_ == null || !(_loc1_ == "WIN") && !(_loc1_ == "MAC"))
         {
            return false;
         }
         var _loc2_:String = Capabilities.version.split(" ")[1];
         if(!(versionCapabDict[_loc2_] == undefined) && !(versionCapabDict[_loc2_] == null))
         {
            return versionCapabDict[_loc2_];
         }
         if(compareVersion(MIN_VERSION_FOR_P2P,_loc2_) > 0)
         {
            return false;
         }
         return true;
      }
      
      public static function checkVersionForStageVideo() : Boolean {
         var _loc1_:String = Capabilities.version.split(" ")[0];
         if(_loc1_ == null || !(_loc1_ == "WIN") && !(_loc1_ == "MAC"))
         {
            return false;
         }
         var _loc2_:String = Capabilities.version.split(" ")[1];
         if(compareVersion(MIN_VERSION_FOR_STAGEVIDEO,_loc2_) > 0)
         {
            return false;
         }
         return true;
      }
      
      public static function checkVersionForNewVersion() : Boolean {
         var _loc1_:String = Capabilities.version.split(" ")[0];
         if(_loc1_ == null || !(_loc1_ == "WIN") && !(_loc1_ == "MAC"))
         {
            return false;
         }
         var _loc2_:String = Capabilities.version.split(" ")[1];
         if(compareVersion(MIN_VERSION_FOR_NEWVERSION,_loc2_) > 0)
         {
            return false;
         }
         return true;
      }
      
      public static function compareVersion(param1:String, param2:String) : int {
         var _loc8_:* = 0;
         var _loc9_:* = 0;
         var _loc3_:Array = param1.split(",");
         var _loc4_:Array = param2.split(",");
         var _loc5_:int = Math.min(_loc3_.length,_loc4_.length);
         var _loc6_:* = 0;
         var _loc7_:* = 0;
         while(_loc7_ < _loc5_)
         {
            _loc8_ = parseInt(_loc3_[_loc7_]);
            _loc9_ = parseInt(_loc4_[_loc7_]);
            if(_loc8_ > _loc9_)
            {
               _loc6_ = 1;
               break;
            }
            if(_loc8_ < _loc9_)
            {
               _loc6_ = -1;
               break;
            }
            _loc7_++;
         }
         if(_loc6_ == 0)
         {
            if(_loc3_.length > _loc4_.length)
            {
               _loc6_ = 1;
            }
            else if(_loc3_.length < _loc4_.length)
            {
               _loc6_ = -1;
            }
            
         }
         return _loc6_;
      }
   }
}
